/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.EnderecoDAO;
import Model.Endereco;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

/**
 *
 * @author Maury
 */
public class preparaPesquisarEspaco extends Processor {

    @Override
    public void execute() throws ServletException, IOException {
        try {
            ArrayList<Endereco> enderecos = EnderecoDAO.pesquisarAll();
            
            if(enderecos != null){
                if(!enderecos.isEmpty()){
                    getRequest().setAttribute("enderecos", enderecos);
                    RequestDispatcher rd = getRequest().getRequestDispatcher("pesquisarEspaco.jsp");
                    rd.forward(getRequest(), getResponse());
                }else{
                    throw new ServletException();
                }
            }
            else{
                throw new ServletException();
            }
            
        } catch (SQLException ex) {
            throw new ServletException(ex);
        } catch (ClassNotFoundException ex) {
            throw new ServletException(ex);
        }
    }
        
}
